package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.constant.AdaPayConstant;
import com.tbit.uqbike.client.constant.RechargeConstant;
import com.tbit.uqbike.client.dao.capital.AdaPayLogDao;
import com.tbit.uqbike.client.pojo.newEntity.AdaPayLog;
import com.tbit.uqbike.client.service.AdaPayLogService;
import com.tbit.uqbike.client.util.DoubleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: chen
 * @Description: 分账订单记录
 * @Date: 创建于 11:06 2021/9/26
 */
@Service
public class AdaPayLogServiceImpl implements AdaPayLogService {

    @Autowired
    private AdaPayLogDao adaPayLogDao;

    @Override
    public void add(AdaPayLog adaPayLog) {
        adaPayLog.setAddTime(new Date());
        adaPayLog.setMoney(DoubleUtil.parseDouble(adaPayLog.getMoney()));
        adaPayLogDao.add(adaPayLog);
    }


    @Override
    public AdaPayLog getByOrderNO(String orderNO) {
        return adaPayLogDao.getByOrderNO(orderNO);
    }

    @Override
    public AdaPayLog getByAdaPayId(String adaPayId) {
        return adaPayLogDao.getByAdaPayId(adaPayId);
    }

    @Override
    public void edit(AdaPayLog adaPayLog) {
        if (adaPayLog.getCashMoney() != null) {
            adaPayLog.setCashMoney(DoubleUtil.parseDouble(adaPayLog.getCashMoney()));
        }
        adaPayLogDao.edit(adaPayLog);
    }

    @Override
    public void editRefund(AdaPayLog adaPayLog) {
        adaPayLog.setRefundTime(new Date());
        if (adaPayLog.getRefundMoney() != null) {
            adaPayLog.setRefundMoney(DoubleUtil.parseDouble(adaPayLog.getRefundMoney()));
        }
        adaPayLogDao.editRefund(adaPayLog);
    }

    @Override
    public List<AdaPayLog> getByUserId(Integer userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        //map.put("type", RechargeConstant.recharge_pay);
        map.put("state", AdaPayConstant.ADAPAY_LOG_PAY);
        return adaPayLogDao.getByUserId(map);
    }

    @Override
    public List<AdaPayLog> getUserCash(Integer userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        //map.put("type", RechargeConstant.recharge_pay);
        map.put("state", AdaPayConstant.ADAPAY_LOG_CASH);
        return adaPayLogDao.getByUserId(map);
    }

    @Override
    public AdaPayLog getByConfirmId(String confirmId) {
        String adaPayId = adaPayLogDao.getPaymentIdByConfirmId(confirmId);
        if (adaPayId == null) {
            return null;
        }
        return adaPayLogDao.getByConfirmId(adaPayId);
    }
}
